using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;

/// <summary>
/// Summary description for Login
/// </summary>
public class Login
{
    public Login()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public void login(string username, string password)
    {
        Database db = DatabaseFactory.CreateDatabase(ConfigurationManager.AppSettings["ConnectionStringName"]);
        DbCommand comLogin;
        try
        {
            comLogin = db.GetSqlStringCommand("select bloggi_bloggi.UserValidate(@Email, @Password)");
            comLogin.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Email", username));
            comLogin.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", password));
            int userId = int.Parse(db.ExecuteScalar(comLogin).ToString());
            if (userId > 0)
            {
                SessionHelper<int>.setVar("UserId", userId);
            }
            comLogin.Dispose();
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
        }
    }
}
